namespace SinaFinance.ChartLibrary.AxisLibrary
{
    using SinaFinanceBaseClassLibrary;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Animation;

    public partial class KLineAxis : UserControl
    {
        //private bool _contentLoaded;
        private AxisSysKline axis = new AxisSysKline();
        private double bottomSpan = 0.0;
        private Canvas coverCanvas = new Canvas();
        private int keyFramesAmount = 20;
        private List<KPoint> kLinePoints;
        //internal Grid LayoutRoot;
        private double leftSpan = 0.0;
        private double rightSpan = 0.0;
        //internal Canvas rootCanvas;
        private Storyboard storyboard_CanvasTranslateTransform = new Storyboard();
        private Storyboard storyboard_CanvasWidth = new Storyboard();
        private double topSpan = 0.0;
        private List<SplineDoubleKeyFrame> TranslateTransforKeyFrameList = new List<SplineDoubleKeyFrame>();
        private DoubleAnimationUsingKeyFrames TranslateTransformAnimation = new DoubleAnimationUsingKeyFrames();
        private DoubleAnimationUsingKeyFrames WidthAnimation = new DoubleAnimationUsingKeyFrames();
        private List<SplineDoubleKeyFrame> WidthtKeyFrameList = new List<SplineDoubleKeyFrame>();
        private List<string> xAxisTips = new List<string>();
        private List<string> yAxisTips = new List<string>();

        public KLineAxis()
        {
            this.InitializeComponent();
            if (base.Width <= 0.0)
            {
                base.Width = 600.0;
            }
            if (base.Height <= 0.0)
            {
                base.Height = 400.0;
            }
            base.Loaded += new RoutedEventHandler(this.KLineAxis_Loaded);
        }

        public void BeginTimeSharingLineStoryboard()
        {
            double num = this.coverCanvas.Width / ((double) this.keyFramesAmount);
            for (int i = 0; i < this.keyFramesAmount; i++)
            {
                this.WidthtKeyFrameList[i].KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double) (i * 0.2)));
                this.WidthtKeyFrameList[i].Value = this.coverCanvas.Width - (num * (i + 1));
                this.TranslateTransforKeyFrameList[i].KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double) (i * 0.2)));
                this.TranslateTransforKeyFrameList[i].Value = num * (i + 1);
            }
            this.storyboard_CanvasWidth.Begin();
            this.storyboard_CanvasTranslateTransform.Begin();
            this.storyboard_CanvasWidth.Completed += new System.EventHandler(this.storyboard_CanvasWidth_Completed);
            this.storyboard_CanvasTranslateTransform.Completed += new System.EventHandler(this.storyboard_CanvasTranslateTransform_Completed);
        }

        //[DebuggerNonUserCode]
        //public void InitializeComponent()
        //{
        //    if (!this._contentLoaded)
        //    {
        //        this._contentLoaded = true;
        //        Application.LoadComponent(this, new Uri("/SinaFinance;component/ChartLibrary/AxisLibrary/KLineAxis.xaml", UriKind.Relative));
        //        this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
        //        this.rootCanvas = (Canvas) base.FindName("rootCanvas");
        //    }
        //}

        private void KLineAxis_Loaded(object sender, RoutedEventArgs e)
        {
            int num;
            SplineDoubleKeyFrame frame;
            LinearGradientBrush brush = new LinearGradientBrush();
            GradientStop stop = new GradientStop();
            GradientStop stop2 = new GradientStop();
            stop.Color = Color.FromArgb(0xff, 0, 0, 0);
            stop.Offset = 0.0;
            stop2.Color = Color.FromArgb(0xff, 0x13, 0x1b, 0x29);
            stop2.Offset = 1.0;
            brush.StartPoint = new Point(0.0, 0.0);
            brush.EndPoint = new Point(0.0, 1.0);
            brush.GradientStops.Add(stop);
            brush.GradientStops.Add(stop2);
            this.rootCanvas.Background = brush;
            this.axis.Width = base.Width;
            this.axis.Height = base.Height;
            this.axis.LeftSpan = this.leftSpan;
            this.axis.RightSpan = this.rightSpan;
            this.axis.KLinePoints = this.kLinePoints;
            this.axis.ParentCanvas = this.rootCanvas;
            this.axis.TopSpan = this.topSpan;
            this.axis.BottomSpan = this.bottomSpan;
            this.axis.YAxisTips = this.yAxisTips;
            this.axis.XAxisTips = this.xAxisTips;
            this.axis.KLinePoints = this.kLinePoints;
            this.axis.RenderAxisSys();
            TransformGroup group = new TransformGroup();
            ScaleTransform transform = new ScaleTransform();
            SkewTransform transform2 = new SkewTransform();
            RotateTransform transform3 = new RotateTransform();
            TranslateTransform transform4 = new TranslateTransform();
            group.Children.Add(transform);
            group.Children.Add(transform2);
            group.Children.Add(transform3);
            group.Children.Add(transform4);
            this.coverCanvas.RenderTransform = group;
            this.coverCanvas.Width = this.axis.pointRightTop.X - this.axis.pointLeftTop.X;
            this.coverCanvas.Height = this.axis.pointRightBottom.Y - this.axis.pointRightTop.Y;
            this.coverCanvas.Margin = new Thickness(this.axis.pointLeftTop.X + 1.0, this.axis.pointLeftTop.Y, 0.0, 0.0);
            this.coverCanvas.SetValue(Canvas.ZIndexProperty, 15);
            this.coverCanvas.SetValue(FrameworkElement.NameProperty, ReferenceTypeConvertToObject("timeSharingCoverCanvas"));
            this.coverCanvas.Background = brush;
            if (!this.rootCanvas.Children.Contains(this.coverCanvas))
            {
                this.rootCanvas.Children.Add(this.coverCanvas);
            }
            base.Resources.Remove("WidthStoryboard");
            base.Resources.Remove("TranslateTransformStoryboard");
            base.Resources.Add("WidthStoryboard", this.storyboard_CanvasWidth);
            base.Resources.Add("TranslateTransformStoryboard", this.storyboard_CanvasTranslateTransform);
            this.storyboard_CanvasWidth.Stop();
            this.storyboard_CanvasTranslateTransform.Stop();
            this.WidthAnimation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(FrameworkElement.Width)", new object[0]));
            this.WidthAnimation.SetValue(Storyboard.TargetNameProperty, ReferenceTypeConvertToObject("timeSharingCoverCanvas"));
            this.TranslateTransformAnimation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)", new object[0]));
            this.TranslateTransformAnimation.SetValue(Storyboard.TargetNameProperty, ReferenceTypeConvertToObject("timeSharingCoverCanvas"));
            for (num = 0; num < this.keyFramesAmount; num++)
            {
                frame = new SplineDoubleKeyFrame();
                this.WidthAnimation.KeyFrames.Add(frame);
                this.WidthtKeyFrameList.Add(frame);
            }
            for (num = 0; num < this.keyFramesAmount; num++)
            {
                frame = new SplineDoubleKeyFrame();
                this.TranslateTransformAnimation.KeyFrames.Add(frame);
                this.TranslateTransforKeyFrameList.Add(frame);
            }
            this.storyboard_CanvasWidth.Children.Add(this.WidthAnimation);
            this.storyboard_CanvasTranslateTransform.Children.Add(this.TranslateTransformAnimation);
            this.BeginTimeSharingLineStoryboard();
        }

        public static object ReferenceTypeConvertToObject(object color)
        {
            object obj2 = new object();
            return color;
        }

        private void storyboard_CanvasTranslateTransform_Completed(object sender, EventArgs e)
        {
            this.storyboard_CanvasTranslateTransform.Stop();
            this.storyboard_CanvasTranslateTransform.Children.Clear();
        }

        private void storyboard_CanvasWidth_Completed(object sender, EventArgs e)
        {
        }

        public double BottomSpan
        {
            get
            {
                return this.bottomSpan;
            }
            set
            {
                this.bottomSpan = value;
            }
        }

        public List<KPoint> KLinePoints
        {
            get
            {
                return this.kLinePoints;
            }
            set
            {
                this.kLinePoints = value;
            }
        }

        public double LeftSpan
        {
            get
            {
                return this.leftSpan;
            }
            set
            {
                this.leftSpan = value;
            }
        }

        public double RightSpan
        {
            get
            {
                return this.rightSpan;
            }
            set
            {
                this.rightSpan = value;
            }
        }

        public double TopSpan
        {
            get
            {
                return this.topSpan;
            }
            set
            {
                this.topSpan = value;
            }
        }

        public List<string> XAxisTips
        {
            get
            {
                return this.xAxisTips;
            }
            set
            {
                this.xAxisTips = value;
            }
        }

        public List<string> YAxisTips
        {
            get
            {
                return this.yAxisTips;
            }
            set
            {
                this.yAxisTips = value;
            }
        }
    }
}
